package com.huawei.appmarket.service.store.awk.card;

import android.app.Activity;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.util.SparseArray;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.BaseAdapter;
import android.widget.Gallery.LayoutParams;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import androidx.core.view.ViewCompat;
import com.huawei.appgallery.foundation.ui.framework.cardframe.bean.BaseCardBean;
import com.huawei.appgallery.foundation.ui.framework.cardkit.bean.CardBean;
import com.huawei.appmarket.framework.widget.BannerGallery;
import com.huawei.appmarket.service.store.awk.support.BannerAbsCard;
import com.huawei.hms.support.hianalytics.HiAnalyticsConstant;
import java.util.ArrayList;
import java.util.List;
import o.azb;
import o.ccz;
import o.cgz;
import o.chy;
import o.dge.d;
import o.dgh;
import o.dgm;
import o.djv;
import o.dof;
import o.ContentManager;
import o.dyk;
import o.eiz;
import o.eje;
import o.epr;
import o.epv;
import o.CollectCheck;
import o.eqx;
import o.evt;
import o.ewm;
import o.ewm.e;
import o.ewm.h;
import o.ewm.j;
import o.ewm.n;

public class BannerCard extends BannerAbsCard implements OnItemSelectedListener, OnItemClickListener {
    private d ʻ;
    private SparseArray<BaseCardBean> ʼ = new SparseArray();
    private BannerGallery ʽ;
    private Drawable ˊॱ = ContentManager.getInstant().getContext().getResources().getDrawable(e.ॱˎ);
    private d ˋ;
    private boolean ˋॱ = true;
    private int ˏॱ = -1;
    private Drawable ͺ = ContentManager.getInstant().getContext().getResources().getDrawable(e.ʻॱ);
    private djv ॱˊ;
    private chy ॱˋ;
    private eje ॱˎ;
    private List<ImageView> ॱॱ;
    private Context ॱᐝ;
    private LinearLayout ᐝ;

    public class BannerPagerAdapter extends BaseAdapter {
        private List<BaseCardBean> mBannerData = new ArrayList();
        private int preOffset = -1;

        class a {
            final /* synthetic */ BannerPagerAdapter ˊ;
            public ImageView ˋ;
            public TextView ˏ;

            private a(BannerPagerAdapter bannerPagerAdapter) {
                this.ˊ = bannerPagerAdapter;
            }
        }

        public int getPreOffset() {
            return this.preOffset;
        }

        public void setPreOffset(int i) {
            this.preOffset = i;
        }

        public void add(BaseCardBean baseCardBean) {
            this.mBannerData.add(baseCardBean);
        }

        public void clear() {
            this.mBannerData.clear();
        }

        public int getCount() {
            int size = this.mBannerData.size();
            if (size > 1) {
                return 2000;
            }
            return size;
        }

        public void notifyBannerCycle() {
            int count = getCount();
            if (count >= 1) {
                if (count == 1) {
                    BannerCard.this.ʽ.setSelection(0);
                } else {
                    count = this.mBannerData.size();
                    if (count > 1) {
                        if (-1 >= getPreOffset() || getPreOffset() >= getCount()) {
                            BannerCard.this.ʽ.setSelection(count * (1000 / count));
                        } else {
                            BannerCard.this.ʽ.setSelection(getPreOffset());
                        }
                    }
                }
                BannerCard.this.ˎ(BannerCard.this.ʽ.getSelectedItemPosition());
                BannerCard.this.ʽ.ˏ(getCount());
            }
        }

        public Object getItem(int i) {
            if (i < getCount()) {
                return (BaseCardBean) this.mBannerData.get(i % this.mBannerData.size());
            }
            return null;
        }

        public long getItemId(int i) {
            return (long) i;
        }

        public View getView(int i, View view, ViewGroup viewGroup) {
            a aVar;
            if (view == null) {
                view = LayoutInflater.from(ContentManager.getInstant().getContext()).inflate(h.ᐨ, viewGroup, false);
                aVar = new a();
                aVar.ˋ = (ImageView) view.findViewById(j.ՙ);
                aVar.ˏ = (TextView) view.findViewById(j.ㆍʼ);
                ViewCompat.setImportantForAccessibility(aVar.ˋ, 2);
                view.setTag(aVar);
            } else {
                aVar = (a) view.getTag();
            }
            int[] ˊ = BannerCard.this.ॱॱ();
            view.setLayoutParams(new LayoutParams(ˊ[0], ˊ[1]));
            BaseCardBean baseCardBean = (BaseCardBean) getItem(i);
            if (baseCardBean != null) {
                BannerCard.this.ʼ.put(i, baseCardBean);
                BannerCard.this.ˎ(aVar.ˋ, baseCardBean.ˑॱ(), baseCardBean.ॱˌ());
                BannerCard.this.ˋ(aVar.ˏ, baseCardBean.ˋʻ());
            } else {
                view.setVisibility(8);
            }
            return view;
        }
    }

    public /* synthetic */ CardBean ˌ() {
        return ˊ();
    }

    public BannerCard(Context context) {
        super(context);
        this.ॱᐝ = context;
        this.ˋ = new d(context, n.ᐧ);
        this.ʻ = new d(context, n.ᐝˋ);
    }

    public void ˏ(boolean z) {
        this.ˋॱ = z;
    }

    public BaseCardBean ˊ() {
        if (this.ˊᐝ instanceof BaseCardBean) {
            return (BaseCardBean) this.ˊᐝ;
        }
        return null;
    }

    public cgz ˏ(View view) {
        int dimensionPixelSize;
        this.ʽ = (BannerGallery) view.findViewById(j.י);
        this.ʽ.setCallbackDuringFling(false);
        this.ʽ.setOnItemSelectedListener(this);
        this.ʽ.setOnItemClickListener(this);
        this.ʽ.setPadding(0, 0, 0, 0);
        this.ʽ.setUnselectedAlpha(1.0f);
        this.ᐝ = (LinearLayout) view.findViewById(j.ـॱ);
        Resources resources = ContentManager.getInstant().getContext().getResources();
        if (epv.ʼ(ContentManager.getInstant().getContext())) {
            if (this.ˋॱ) {
                dimensionPixelSize = resources.getDimensionPixelSize(ewm.d.ꜟ);
            } else {
                this.ʽ.setSupportImmerse(false);
                dimensionPixelSize = resources.getDimensionPixelSize(ewm.d.ꜟ);
            }
            this.ʽ.setSpacing(0);
        } else {
            this.ʽ.setSpacing((int) resources.getDimension(ewm.d.ʹ));
            dimensionPixelSize = resources.getDimensionPixelSize(ewm.d.ˊˋ);
        }
        this.ᐝ.setPadding(0, 0, 0, dimensionPixelSize);
        this.ᐝ.setGravity(81);
        ʽ(view);
        return this;
    }

    public void ˊ(double d) {
        this.ˋˊ = d;
        this.ˊˊ = d;
    }

    public void ॱ(double d) {
        this.ˋˊ = d;
    }

    public void ˎ(double d) {
        this.ˊˊ = d;
    }

    private boolean ʻ() {
        return Double.compare(this.ˊˊ, 6.0d) == 0 && Double.compare(this.ˋˊ, 3.0d) == 0;
    }

    public void ॱ(ImageView imageView) {
        if (this.ॱॱ == null) {
            this.ॱॱ = new ArrayList();
        }
        this.ॱॱ.add(imageView);
        this.ᐝ.addView(imageView);
    }

    public void ˎ() {
        if (this.ॱॱ != null) {
            this.ॱॱ.clear();
        }
        if (this.ᐝ != null) {
            this.ᐝ.removeAllViews();
        }
    }

    public void ˏ(BannerPagerAdapter bannerPagerAdapter) {
        this.ʽ.setAdapter(bannerPagerAdapter);
    }

    private void ˎ(int i) {
        if (!CollectCheck.isEmpty(this.ॱॱ)) {
            int size = i % this.ॱॱ.size();
            if (size < this.ॱॱ.size()) {
                if (this.ˏॱ > -1) {
                    ((ImageView) this.ॱॱ.get(this.ˏॱ % this.ॱॱ.size())).setImageDrawable(this.ͺ);
                }
                ((ImageView) this.ॱॱ.get(size)).setImageDrawable(this.ˊॱ);
            }
        }
    }

    private int[] ॱॱ() {
        int ˎ;
        int i;
        if (!epr.ˎ().ॱॱ() || ʻ()) {
            ˎ = epv.ˎ(this.ॱᐝ);
            i = (int) (((double) ˎ) / this.ˋˊ);
        } else {
            i = azb.ॱ(this.ॱᐝ);
            if (azb.ˎ(ContentManager.getInstant().getContext())) {
                ˎ = i / 2;
                i = (int) (((double) ˎ) / this.ˊˊ);
            } else {
                ˎ = (i * 3) / 4;
                i = (int) (((double) ˎ) / this.ˋˊ);
            }
        }
        return new int[]{ˎ, i};
    }

    public void ˎ(ImageView imageView, String str, String str2) {
        eqx.ˎ(imageView, str2);
    }

    public void onItemSelected(AdapterView<?> adapterView, View view, int i, long j) {
        if (this.ʽ != null) {
            BannerPagerAdapter bannerPagerAdapter = (BannerPagerAdapter) this.ʽ.getAdapter();
            if (bannerPagerAdapter != null) {
                bannerPagerAdapter.setPreOffset(i);
                BaseCardBean baseCardBean = (BaseCardBean) bannerPagerAdapter.getItem(i);
                if (baseCardBean != null) {
                    ˊ(baseCardBean, true);
                    ॱ(baseCardBean);
                }
            }
        }
        ˎ(i);
        this.ˏॱ = i;
        if (this.ॱˊ != null) {
            this.ॱˊ.ˏ(view);
        }
    }

    private void ˊ(BaseCardBean baseCardBean, boolean z) {
        String str = "";
        if (ˋ() != null) {
            str = String.valueOf(ˋ().ˎ());
        }
        str = eiz.ˊ(str + HiAnalyticsConstant.REPORT_VAL_SEPARATOR + dof.ʼ(baseCardBean.ॱॱ()).replaceAll("\\|", "#$#") + HiAnalyticsConstant.REPORT_VAL_SEPARATOR + baseCardBean.u_());
        if (z) {
            dgh.onEvent(this.ˋ.ˏ(str).ˋ());
        } else {
            dgh.onEvent(this.ʻ.ˏ(str).ˋ());
        }
    }

    public void onNothingSelected(AdapterView<?> adapterView) {
    }

    public eje ˋ() {
        return this.ॱˎ;
    }

    public void ˎ(eje o_eje) {
        this.ॱˎ = o_eje;
    }

    public void ˊ(chy o_chy) {
        this.ॱˋ = o_chy;
    }

    public void onItemClick(AdapterView<?> adapterView, View view, int i, long j) {
        BaseCardBean baseCardBean = (BaseCardBean) this.ʼ.get(i);
        if (baseCardBean != null) {
            this.ˊᐝ = baseCardBean;
            if (this.ॱˋ != null) {
                this.ॱˋ.ˏ(0, this);
            }
            ˊ(baseCardBean, false);
        }
    }

    public void ˏ(djv o_djv) {
        this.ॱˊ = o_djv;
    }

    public ArrayList<String> ˊ(BannerPagerAdapter bannerPagerAdapter) {
        if (this.ʽ == null || bannerPagerAdapter == null) {
            return null;
        }
        BaseCardBean baseCardBean = (BaseCardBean) bannerPagerAdapter.getItem(this.ʽ.getSelectedItemPosition());
        if (baseCardBean == null) {
            return null;
        }
        ArrayList<String> arrayList = new ArrayList();
        arrayList.add(baseCardBean.ॱॱ() + "#$#" + baseCardBean.u_());
        return arrayList;
    }

    private void ॱ(BaseCardBean baseCardBean) {
        if (evt.ˊ(ˉ()) >= 50) {
            if (ˋ() != null) {
                baseCardBean.ˋˋ(String.valueOf(ˋ().ˎ()));
            }
            int ॱ = ccz.ॱ();
            if (this.ʽ != null) {
                ॱ = dgm.ˎ((Activity) this.ʽ.getContext());
            }
            new dyk(ॱ).ॱ(baseCardBean);
        }
    }
}
